package com.blog.admin.mapper;

import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import com.blog.admin.pojo.auth.Permission;

import java.util.List;
import java.util.Set;
@Component
public interface PermissionMapper {
    List<Permission> selectAll();

    @Select("SELECT p.permission FROM user_role ur LEFT JOIN user u ON u.id = ur.user_id \n" +
            "LEFT JOIN role r ON ur.role_id=r.id LEFT JOIN role_permission rp ON ur.role_id = rp.role_id\n" +
            "LEFT JOIN permission p ON p.id = rp.permission_id\n" +
            "WHERE u.id=#{userId}")
    Set<String> findRoleNameByUserId(@Param("userId") int userId);

    /**
     * 获取所有一级菜单
     * @return
     */
	List<Permission> getAllMenu();

	/**
     * 根据用户id获取所有一级菜单
     * @return
     */
	List<Permission> getMenusByUserId(Integer id);

	/**
	 * 根据一级菜单id获取二级菜单
	 * @param id
	 * @return
	 */
	List<Permission> getAllMenus(Integer id);

	/**
	 * 获取所有的菜单
	 * @param id
	 * @return
	 */
	List<Permission> getAllPermission(Integer id);

	/*
	 * 获取所有的权限
	 */
	List<Permission> getAllPermission();

	/**
	 * 根据角色获取权限
	 * @param id
	 * @return
	 */
	List<String> getMenuByrRole(Integer id);

	/**
	 * 获取用户所有菜单
	 * @param id
	 * @return
	 */
	List<Permission> getMenuTreesByUserId(Integer id);

	List<Permission> getAllMenus();

	/**
	 * 删除权限
	 * @param id
	 * @return
	 */
	Integer deletePermission(Integer id);

	Permission getPermissionById(Integer id);

	/**
	 * 更新
	 * @param permission
	 * @return
	 */
	Integer update(Permission permission);

	/**
	 * 添加
	 * @param permission
	 * @return
	 */
	Integer insert(Permission permission);
}